#include "gtkprivate.h"
#include "gtkintl.h"
-
/**
* SECTION:gtktextbuffer
* @Short_description: Stores attributed text for display in a GtkTextView
* types related to the text widget and how they work together.
*/
-
typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
struct _GtkTextBufferPrivate
guint has_selection : 1;
};
-
typedef struct _ClipboardRequest ClipboardRequest;
struct _ClipboardRequest
static void gtk_text_buffer_free_target_lists (GtkTextBuffer *buffer);
-static guint signals[LAST_SIGNAL] = { 0 };
-
static void gtk_text_buffer_set_property (GObject *object,
guint prop_id,
const GValue *value,
static void gtk_text_buffer_notify (GObject *object,
GParamSpec *pspec);
+static guint signals[LAST_SIGNAL] = { 0 };
+
G_DEFINE_TYPE_WITH_PRIVATE (GtkTextBuffer, gtk_text_buffer, G_TYPE_OBJECT)
static void
GtkTextIter end;
gboolean retval = FALSE;
const PangoLogAttr *attrs;
- int offset;
gboolean backspace_deletes_character;
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
/* For no good reason, attrs is NULL for the empty last line in
* a buffer. Special case that here. (#156164)
*/
- if (attrs)
+ if (attrs != NULL)
{
- offset = gtk_text_iter_get_line_offset (&start);
+ gint offset = gtk_text_iter_get_line_offset (&start);
backspace_deletes_character = attrs[offset].backspace_deletes_character;
}
else
static void
free_log_attr_cache (GtkTextLogAttrCache *cache)
{
- gint i = 0;
- while (i < ATTR_CACHE_SIZE)
- {
- g_free (cache->entries[i].attrs);
- ++i;
- }
+ gint i;
+
+ for (i = 0; i < ATTR_CACHE_SIZE; i++)
+ g_free (cache->entries[i].attrs);
+
g_slice_free (GtkTextLogAttrCache, cache);
}
static void
clear_log_attr_cache (GtkTextLogAttrCache *cache)
{
- gint i = 0;
- while (i < ATTR_CACHE_SIZE)
+ gint i;
+
+ for (i = 0; i < ATTR_CACHE_SIZE; i++)
{
g_free (cache->entries[i].attrs);
cache->entries[i].attrs = NULL;
- ++i;
}
}
g_assert (char_len > 0);
- if (char_lenp)
+ if (char_lenp != NULL)
*char_lenp = char_len;
-
+
attrs = g_new (PangoLogAttr, char_len + 1);
/* FIXME we need to follow PangoLayout and allow different language
/* The return value from this is valid until you call this a second time.
*/
-const PangoLogAttr*
+const PangoLogAttr *
_gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
const GtkTextIter *anywhere_in_line,
gint *char_len)
if (gtk_text_iter_is_end (anywhere_in_line) &&
gtk_text_iter_get_line_offset (anywhere_in_line) == 0)
{
- if (char_len)
+ if (char_len != NULL)
*char_len = 0;
return NULL;
}
cache = priv->log_attr_cache;
line = gtk_text_iter_get_line (anywhere_in_line);
- i = 0;
- while (i < ATTR_CACHE_SIZE)
+ for (i = 0; i < ATTR_CACHE_SIZE; i++)
{
- if (cache->entries[i].attrs &&
+ if (cache->entries[i].attrs != NULL &&
cache->entries[i].line == line)
{
- if (char_len)
+ if (char_len != NULL)
*char_len = cache->entries[i].char_len;
return cache->entries[i].attrs;
}
- ++i;
}
-
+
/* Not in cache; open up the first cache entry */
g_free (cache->entries[ATTR_CACHE_SIZE-1].attrs);
cache->entries[0].attrs = compute_log_attrs (anywhere_in_line,
&cache->entries[0].char_len);
- if (char_len)
+ if (char_len != NULL)
*char_len = cache->entries[0].char_len;
-
+
return cache->entries[0].attrs;
}
static gboolean
is_word_end_func (const PangoLogAttr *attrs,
- gint offset,
- gint min_offset,
- gint len)
+ gint offset,
+ gint min_offset,
+ gint len)
{
return attrs[offset].is_word_end;
}
static gboolean
is_word_start_func (const PangoLogAttr *attrs,
- gint offset,
- gint min_offset,
- gint len)
+ gint offset,
+ gint min_offset,
+ gint len)
{
return attrs[offset].is_word_start;
}
static gboolean
inside_word_func (const PangoLogAttr *attrs,
- gint offset,
- gint min_offset,
- gint len)
+ gint offset,
+ gint min_offset,
+ gint len)
{
/* Find next word start or end */
while (offset >= min_offset &&
static gboolean
is_sentence_end_func (const PangoLogAttr *attrs,
- gint offset,
- gint min_offset,
- gint len)
+ gint offset,
+ gint min_offset,
+ gint len)
{
return attrs[offset].is_sentence_end;
}
static gboolean
is_sentence_start_func (const PangoLogAttr *attrs,
- gint offset,
- gint min_offset,
- gint len)
+ gint offset,
+ gint min_offset,
+ gint len)
{
return attrs[offset].is_sentence_start;
}
static gboolean
inside_sentence_func (const PangoLogAttr *attrs,
- gint offset,
- gint min_offset,
- gint len)
+ gint offset,
+ gint min_offset,
+ gint len)
{
/* Find next sentence start or end */
while (offset >= min_offset &&
{
gint char_len;
const PangoLogAttr *attrs;
- int offset;
+ gint offset;
gboolean result = FALSE;
g_return_val_if_fail (iter != NULL, FALSE);
/* char_len may be 0 and attrs will be NULL if so, if
* iter is the end iter and the last line is empty.
- *
+ *
* offset may be equal to char_len, since attrs contains an entry
- * for one past the end
+ * for one past the end.
*/
-
- if (attrs && offset <= char_len)
+ if (attrs != NULL && offset <= char_len)
result = (* func) (attrs, offset, 0, char_len);
return result;
{
gint char_len;
const PangoLogAttr *attrs;
- int offset;
+ gint offset;
gboolean result = FALSE;
g_return_val_if_fail (iter != NULL, FALSE);
offset = gtk_text_iter_get_line_offset (iter);
/* char_len may be 0 and attrs will be NULL if so, if
- * iter is the end iter and the last line is empty
+ * iter is the end iter and the last line is empty.
*/
-
- if (attrs)
+ if (attrs != NULL)
result = (* func) (attrs, offset, char_len, found_offset,
already_moved_initially);